package com.zhao.dota.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

@Slf4j
public class ParseWatch {

    private final Long matchId;

    private final long startTime;

    private long lastTime;

    private String lastName;

    private boolean watching;

    public ParseWatch(Long matchId) {
        this.matchId = matchId;
        startTime = System.currentTimeMillis();
        log.info("[{}]录像开始解析", matchId);
    }

    public void start(String name) {
        Assert.hasText(name, "name不能为空");
        if (watching) {
            end();
        }
        watching = true;
        log.info("[{}]{}开始", matchId, name);
        this.lastName = name;
        this.lastTime = System.currentTimeMillis();
    }

    public void end() {
        watching = false;
        log.info("[{}]{}结束，用时：{} ms", matchId, lastName, (System.currentTimeMillis() - lastTime));
    }

    public void finish() {
        log.info("[{}]录像解析完成，总用时: {}ms", matchId, (System.currentTimeMillis() - startTime));
    }

}
